﻿CREATE PROCEDURE [dbo].[usp_update_BatchResubmissionMessage]
	@ID INT,
	@Status NVARCHAR(25),
	@ErrorMessage VARCHAR(MAX)
AS

	UPDATE BatchResubmissionMessage
		SET [Status] = @Status
		,	[ErrorMessage] = @ErrorMessage
		,	[LastModified] = GETDATE()
	WHERE ID = @ID

	UPDATE m
		SET m.ResubmitAttempted = 1
			,m.ResubmitSuccessful = CASE WHEN @Status = 'Completed' THEN 1 ELSE 0 END 
	FROM
		[Message] m JOIN
		[BatchResubmissionMessage] brm ON 
			brm.MessageID = m.MessageID 
			AND brm.ID = @ID

RETURN 0
